import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

function getDefaultCity(){
  var defaultCity;
  if(localStorage.getItem("city")){
    defaultCity = localStorage.getItem("city")
  }else{
    defaultCity = "武汉"
  }
  return defaultCity
}

export default new Vuex.Store({
  state: {
    city:getDefaultCity()
  },
  mutations: {
    changeStateCity(state,val){
      // console.log(state)
      // console.log(val)
      localStorage.setItem("city",val)
      state.city = val
    }
  },
  actions: {
    handleClick(ctx,val){
      ctx.commit("changeStateCity",val)
    }
  },
  modules: {
  }
})
